package freemarker.ext.beans

/** For strange reason, FM is not letting subclass to work with BeansModelCache 
 * outside of it's own package! This is the current work around for how.
 * 
 
 NOT IN USE YET.
class ScalaModelCache(val wrapper: BeansWrapper) extends BeansModelCache(wrapper)

 */

/*
FAILED CASE 1:
package _root_ {
  package freemarker{
    package ext{
      package beans{
         class ScalaModelCache(val wrapper: BeansWrapper) extends _root_.freemarker.ext.beans.BeansModelCache(wrapper)
      }
    }
  }
}
*/  

/*
FAILED CASE 2:
 //We have to provide this modelcache, which ported from BeansModelCache because they
 // locked their constructor with package access only! What a pitty.
 
class ScalaModelCache(val wrapper: BeansWrapper) extends ModelCache {
  val classToFactory = new jutil.HashMap[Class[_], ModelFactory]
  val mappedClassNames = new jutil.HashSet[String]()
    
  def isCacheable(obj: Object) = obj.getClass() != classOf[java.lang.Boolean]
  
  def create(obj: Object): TemplateModel = {
      val clazz = obj.getClass()

      val factory = classToFactory.synchronized{
          var fac = classToFactory.get(clazz)
          if(fac == null) {
              val className = clazz.getName()
              // clear mappings when class reloading is detected
              if(!mappedClassNames.add(className)) {
                  classToFactory.clear()
                  mappedClassNames.clear()
                  mappedClassNames.add(className)
              }
              fac = wrapper.getModelFactory(clazz) //Can't call this method!!!! ????
              classToFactory.put(clazz, fac)
          }
          fac
      }
      
      factory.create(obj, wrapper)
  }    
}
*/
